//% color=#5b3fe8
namespace TinyWebDB {
	//% block="TinyWebDB Setting username[user] password[secret]" blockType="command"
    //% user.shadow="string"   user.defl="share"
    //% secret.shadow="string"   secret.defl="everyone"
    export function TinyWebDBInit(parameter: any, block: any){
        let user = parameter.user.code;
        let secret = parameter.secret.code;
		Generator.addInclude('includeTinywebdb', '#include <mPython_tinywebdb.h>');
		Generator.addObject(`TinyWebDBObject`, `mPython_TinyWebDB`, `mydb;`);
		Generator.addCode(`mydb.setServerParameter("http://tinywebdb.appinventor.space/api", ${user},${secret});`);
	
    }
	
	
    //% block="network connection test" blockType="reporter"
    export function testInternetConnect(parameter: any, block: any){
        Generator.addCode(`mydb.testInternetConnect()`);
    }	
	

	
     //% block="Update Tag[tag] Value[tagValue]" blockType="command"
    //% tag.shadow="string"   tag.defl=""
    //% tagValue.shadow="string"   tagValue.defl=""
    export function Add(parameter: any, block: any){
        let tag = parameter.tag.code;
        let tagValue = parameter.tagValue.code;
        Generator.addCode(`mydb.updateTagValue(${tag},${tagValue});`);
    }	

	
     //% block="Update Tag[tag] Value[tagValue]" blockType="command"
    //% tag.shadow="string"   tag.defl=""
    //% tagValue.shadow="string"   tagValue.defl=""
    export function Update(parameter: any, block: any){
        let tag = parameter.tag.code;
        let tagValue = parameter.tagValue.code;
        Generator.addCode(`mydb.updateTagValue(${tag},${tagValue});`);
    }



    //% block="Get Tag[tag] Value" blockType="reporter"
    //% tag.shadow="string"   tag.defl=""
    export function Get(parameter: any, block: any){
        let tag = parameter.tag.code;
        Generator.addCode(`mydb.getTag(${tag})`);
    }


		
	
    //% block="Delete Tag [tag] Records" blockType="command"
    //% tag.shadow="string"   tag.defl=""
    export function Delete(parameter: any, block: any){
        let tag = parameter.tag.code;
        Generator.addCode(`mydb.deleteTag(${tag});`);
    }
	
		
	
    //% block="Count Database Records" blockType="reporter"
    export function Count(parameter: any, block: any){
        Generator.addCode(`mydb.count()`);
    }
	
	
	

   //% block="Search No[startNum] count[num] tag[tag] type[showtype]" blockType="reporter"
    //% startNum.shadow="number" startNum.defl="1"
    //% num.shadow="number" num.defl="1"
    //% tag.shadow="string"   tag.defl=""
    //% showtype.shadow="dropdown" showtype.options="showtype"
    export function Search(parameter: any, block: any){
        let startNum = parameter.startNum.code;
        let num = parameter.num.code;
        let tag = parameter.tag.code;
        let showtype = parameter.showtype.code;
        Generator.addCode(`mydb.searchTags(${startNum},${num},${tag},${showtype})`);
    }
	

}